package com.ruoyi.manage.service.impl;

import java.util.List;

import com.alibaba.fastjson.JSONObject;
import com.ruoyi.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.manage.mapper.WorksShowMapper;
import com.ruoyi.manage.domain.WorksShow;
import com.ruoyi.manage.service.IWorksShowService;

/**
 * 作品展示Service业务层处理
 * 
 * @author ruoyi
 * @date 2021-03-07
 */
@Service
public class WorksShowServiceImpl implements IWorksShowService 
{
    @Autowired
    private WorksShowMapper worksShowMapper;

    /**
     * 查询作品展示
     * 
     * @param id 作品展示ID
     * @return 作品展示
     */
    @Override
    public WorksShow selectWorksShowById(Long id)
    {
        WorksShow worksShow = worksShowMapper.selectWorksShowById(id);
        String imageList = worksShow.getImageList();
        String videoList = worksShow.getVideoList();
        List image = JSONObject.parseObject(imageList, List.class);
        List video = JSONObject.parseObject(videoList, List.class);
        worksShow.setImageListOb(image);
        worksShow.setVideoListOb(video);
        return worksShow;
    }

    /**
     * 查询作品展示列表
     * 
     * @param worksShow 作品展示
     * @return 作品展示
     */
    @Override
    public List<WorksShow> selectWorksShowList(WorksShow worksShow)
    {
        return worksShowMapper.selectWorksShowList(worksShow);
    }

    /**
     * 新增作品展示
     * 
     * @param worksShow 作品展示
     * @return 结果
     */
    @Override
    public int insertWorksShow(WorksShow worksShow)
    {
        List<String> imageListOb = worksShow.getImageListOb();
        List<String> videoListOb = worksShow.getVideoListOb();
        String image = JSONObject.toJSONString(imageListOb);
        String video = JSONObject.toJSONString(videoListOb);
        worksShow.setImageList(image);
        worksShow.setVideoList(video);
        worksShow.setCreateTime(DateUtils.getNowDate());
        return worksShowMapper.insertWorksShow(worksShow);
    }

    /**
     * 修改作品展示
     * 
     * @param worksShow 作品展示
     * @return 结果
     */
    @Override
    public int updateWorksShow(WorksShow worksShow)
    {
        List<String> imageListOb = worksShow.getImageListOb();
        List<String> videoListOb = worksShow.getVideoListOb();
        String image = JSONObject.toJSONString(imageListOb);
        String video = JSONObject.toJSONString(videoListOb);
        worksShow.setImageList(image);
        worksShow.setVideoList(video);
        return worksShowMapper.updateWorksShow(worksShow);
    }

    /**
     * 批量删除作品展示
     * 
     * @param ids 需要删除的作品展示ID
     * @return 结果
     */
    @Override
    public int deleteWorksShowByIds(Long[] ids)
    {
        return worksShowMapper.deleteWorksShowByIds(ids);
    }

    /**
     * 删除作品展示信息
     * 
     * @param id 作品展示ID
     * @return 结果
     */
    @Override
    public int deleteWorksShowById(Long id)
    {
        return worksShowMapper.deleteWorksShowById(id);
    }
}
